function onActionMenuClick(sAction, iObjType, iObjSubType)
{
	var iX = 400;
	var iY = 200;
	var bClose = false;
	var bReload = false;

	var _oId = new Array(crmFormSubmit.crmFormSubmitId.value);
	var sIds = crmFormSubmit.crmFormSubmitId.value;  //backwards compatibility with grid dialogs
	var sPath = "/_grid/cmds/dlg_" + sAction + ".aspx?iObjType=" + iObjType + "&iTotal=1&sIds=" + sIds;

	switch (sAction)
	{
		case "addquota":		iX = 600;	iY = 425;	sPath += "&uid=" + _oId[0];	break;
		case "applyrule":		iX = 400;	iY = 275;	break;
		case "assign":		iX = 456;	iY = 260;	bClose = true;	break;
		case "actsetrespon":	iX = 456;	iY = 310;	break;
		case "changeorg":		iX = 400;	iY = 275;	bClose = true;	break;
		case "changecaptain":	iX = 400;	iY = 225;	bClose = true;	break;
		case "changeparent":	iX = 400;	iY = 225;	bClose = true;	break;
		case "delete":	iX = 450; iY = 205;

			// since they're deleting the object, we don't care if the form is dirty
			//
			crmForm.detachCloseAlert();

			bClose = true;
			break;

		case "activate":
		case "deactivate":
			if (IsActivityTypeCode(iObjType))
			{
				sPath += "&activityMode=1";
			}

			sPath += "&confirmMode=1";

			if (iObjType == BusinessUnit)
			{
				iY = 250;
			}
			break;

		case "managelicense":	iX = 640;	iY = 350;	break;
		case "role":			iX = 500;	iY = 335;	break;
		case "share":			iX = 700;	iY = 480;	break;
		case "status":			iX = 456;	iY = 250;	break;
		case "mailmerge":		iX = 450;	iY = 450;	break;
	}

	var o = openStdDlg(sPath, _oId, iX, iY);

	if (o && bClose)
	{
		try
		{
			window.opener.auto(iObjType);
		}
		catch(e)
		{}

		window.close();
	}
	else if (bReload && o)
	{
		parent.location.reload();
		try
		{
			window.opener.auto(iObjType);
		}
		catch(e)
		{}
	}

	return o;
}


function changeState(sAction, iObjType, iFormEventId)
{
	if (!crmForm.IsValid())
	{
		return;
	}

	var o = onActionMenuClick(sAction, iObjType);

	if (o)
	{
		var b = IsActivityTypeCode(iObjType);

		if (b)
		{
			if (!o.iStateCode)
			{
				o = new Object()
				o.iStateCode = "0";
			}

			var oAcStateCode = createHiddenInput( "acStateCode"  , o.iStateCode );
		}

		if (!crmForm.SubmitCrmForm(iFormEventId, true, true, false ) && b)
		{
			// Clean up our intput so it doesn't cause problem later.
			deleteInput( oAcStateCode );
		}
	}
}

function assignObject(objType)
{
	var ret_val;
	var eventCode; //FormEventID from types.cs
	if (objType == Incident)
	{
		eventCode = 49; //FormEventId.IncidentAssignToUser from types.cs
		var sId = crmFormSubmit.crmFormSubmitId.value;		
		ret_val = openStdDlg("/_grid/cmds/dlg_assignqueue.aspx?iObjType=112&iTotal=1&sQType=1&FromIncidentFrm=1&uid=" + sId, new Array(sId), 456, 300);
	}
	else
	{
		eventCode = 47; //FormEventId.Assign from types.cs
		var url = "/_grid/cmds/dlg_frmassign.aspx";
		url += "?pId=" + crmFormSubmit.crmFormSubmitId.value;
		url += "&pType=" + crmFormSubmit.crmFormSubmitObjectType.value;
		url += "&iObjType=" + objType;
		url += "&iTotal=1";  // since formaction.js only deals with one object, this value can be hardcoded

		ret_val = openStdDlg(url, document, 456, 260);

	}

	if ( ret_val )
	{
		//Incident above will return OwnerId only while assigning to another user
		if(ret_val.OwnerId)
		{
			//	force a submit - hack
			//
			crmForm.name.defaultValue = "";
			var oOwnerId = createHiddenInput( "assignOwnerId"  , ret_val.OwnerId );
			var oOwnerType = createHiddenInput( "assignOwnerType"  , ret_val.OwnerType);

			if( !crmForm.SubmitCrmForm(eventCode, true, true, false ) )
			{
				// If the post couldn't succeed (For example, because of validation), we need to clean up our elements
				// so they don't cause problems next time the user tries.
				deleteInput( oOwnerId );
				deleteInput( oOwnerType );
			}
		}
	}

}
